//
//  TextViewController.m
//  简单记事本
//
//  Created by 胡先剑 on 16/3/13.
//  Copyright © 2016年 胡先剑. All rights reserved.
//

#import "AddViewController.h"

@interface AddViewController ()

//文本输入框
@property (weak, nonatomic) IBOutlet UITextView *contentTextView;

@end

@implementation AddViewController

#pragma mark - 视图加载
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.contentTextView.text = self.content;
    
    self.automaticallyAdjustsScrollViewInsets = false;
}

#pragma mark - 点击空白隐藏键盘
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    //隐藏键盘
    [self.view endEditing:YES];
}

#pragma mark - 点击返回按钮触发的事件
- (IBAction)backButton:(UIBarButtonItem *)sender
{
    //返回上一个导航栏页面
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 点击添加按钮触发的事件
- (IBAction)addButton:(UIBarButtonItem *)sender
{
    //获取当前时间
    NSDate  *now = [NSDate  date];
    NSDateFormatter *dateF = [[NSDateFormatter alloc] init];
    [dateF  setDateFormat: @"yyyy-MM-dd"];
    NSString  *time = [dateF stringFromDate: now];
    
    //将数据传给代理人
    [self.delegate Content:self.contentTextView.text andDate:time];
    
    //返回上个导航栏页面 
    [self.navigationController popViewControllerAnimated:YES];
}

@end
